package com.example.yx.demo23;

import org.springframework.beans.MutablePropertyValues;
import org.springframework.validation.DataBinder;

import java.util.Date;

public class TestDataBinder {
    public static void main(String[] args) {
        //执行数据绑定,此时走set、get方法
        MyBean target = new MyBean();
        DataBinder binder = new DataBinder(target);
        //此时走属性域
        binder.initBeanPropertyAccess();
        MutablePropertyValues values = new MutablePropertyValues();
        values.add("a","10");
        values.add("b","hello");
        values.add("c","1999/03/04");
        binder.bind(values);
        System.out.println(target);

    }


    static class MyBean {
        @Override
        public String toString() {
            return "MyBean{" +
                    "a=" + a +
                    ", b='" + b + '\'' +
                    ", c=" + c +
                    '}';
        }

        private int a;
        private String b;
        private Date c;

        public int getA() {
            return a;
        }

        public void setA(int a) {
            this.a = a;
        }

        public String getB() {
            return b;
        }

        public void setB(String b) {
            this.b = b;
        }

        public Date getC() {
            return c;
        }

        public void setC(Date c) {
            this.c = c;
        }


    }
}
